package com.itheima.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/demo3")
public class Servlet1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        resp.setHeader("content-type","text/html;charset=utf-8");
        resp.getWriter().write("<h1>"+name+",欢迎你</h1>");
        //得到请求方式
        String method = req.getMethod();
        System.out.println(method);
        //获取请求虚拟目录
        String contextPath = req.getContextPath();
        System.out.println("虚拟目录"+contextPath);
        //获取url
        StringBuffer requestURL = req.getRequestURL();
        System.out.println("url"+requestURL.toString());
        //获取uri
        String requestURI = req.getRequestURI();
        System.out.println("uri"+requestURI);
        //获取请求参数
        String queryString = req.getQueryString();
        System.out.println("请求参数"+queryString);
        //获取请求头 user-agent 浏览器的版本信息
        String header = req.getHeader("user-agent");
        System.out.println(header);


    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BufferedReader br = req.getReader();
        String s = br.readLine();
        System.out.println("ssssss  "+s);
    }
}